package edu.cuit.avatar.exception;

/**
 * @author <a href="mailto:1020zhaodan@163.com">Adan</a>
 * @version 1.0
 * @date 2025/7/11 14:00
 */
public class CircleTest {
    public static void main(String[] args) {
        try{
            var c1 = new Circle(10);
            //var c2 = new Circle(-10);
            var c3 = new Circle(0);
        } catch (IllegalRadiusException e){
            e.printStackTrace();
        } finally {
            System.out.println("无论异常与否,finally子句最终都会被执行");
        }

        System.out.println("创建Circle实例数:" + Circle.getNumberOfObjects());

        System.out.println(isInteger("110"));//true
        System.out.println(isInteger("ABC"));//true

        System.out.println(test());
    }


    public static boolean isInteger(String s){
        try {
            Integer.parseInt(s);
            return true;
        } catch (NumberFormatException e){
            return false;
        }
    }

    public static int test(){
        int i = 0;
        try{
            int result = 10 / 0;
            System.out.println("没有异常");
            return ++i;
        } catch (Exception e){
            System.out.println("发生了异常");
            return i++; //会将返回值进行挂起 i = 1
        } finally {
            System.out.println("无论异常与否,最终都会被执行");
            return i++;
        }
    }
}
